package com.showmaker.controller;

import com.showmaker.bean.Setmeal;
import com.showmaker.constant.MessageConstant;
import com.showmaker.entity.Result;
import com.showmaker.service.SetmealService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("/setmeal")
public class SetmealController {

    @DubboReference(interfaceClass = SetmealService.class, version = "1.0")
    private SetmealService setmealService;

    /**
     * 查询所有的套餐
     * @return 返回查询的结果
     */
    @RequestMapping("/selectAll")
    public Result selectAll() {
        try {
            List<Setmeal> setmeals = setmealService.selectAll();
            return new Result(true, MessageConstant.GET_SETMEAL_LIST_SUCCESS, setmeals);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.GET_SETMEAL_LIST_FAIL);
        }
    }

    /**
     * 根据id查询套餐的详细信息，包括套餐基本信息，包含的检查项、检查项包含的检查组
     * @param id 要查询的套餐id
     * @return 返回查询的结果
     */
    @RequestMapping("/{id}")
    public Result getSetmeal(@PathVariable Integer id) {
        try {
            Setmeal setmeal = setmealService.getSetmeal(id);
            return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS, setmeal);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.QUERY_SETMEAL_FAIL);
        }
    }
}
